package com.message.push.starter;

import com.message.push.provider.actor.MessagePush;
import com.message.push.provider.model.MessageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Component;

@Component
public class MessagePushService {

    private static final Logger logger = LoggerFactory.getLogger(MessagePushService.class);

    private final ObjectProvider<MessagePush> messageSenderObjectProvider;

    public MessagePushService(ObjectProvider<MessagePush> messageSenderObjectProvider) {
        this.messageSenderObjectProvider = messageSenderObjectProvider;
    }

    public boolean send(MessageInfo sendMessage) {
        for (MessagePush messageSender : messageSenderObjectProvider) {
            if (messageSender.support(sendMessage.getSupplier())) {
                messageSender.send(sendMessage);
            }
        }
        return true;
    }

}
